{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "<a href=\"https://www.bigdatauniversity.com\"><img src=\"https://ibm.box.com/shared/static/cw2c7r3o20w9zn8gkecaeyjhgw3xdgbj.png\" width=\"400\" align=\"center\"></a>\n",
    "\n",
    "<h1><center>K-Nearest Neighbors</center></h1>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "In this Lab you will load a customer dataset, fit the data, and use K-Nearest Neighbors to predict a data point. But what is **K-Nearest Neighbors**?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "**K-Nearest Neighbors** is an algorithm for supervised learning. Where the data is 'trained' with data points corresponding to their classification. Once a point is to be predicted, it takes into account the 'K' nearest points to it to determine it's classification."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "### Here's an visualization of the K-Nearest Neighbors algorithm.\n",
    "\n",
    "<img src=\"https://ibm.box.com/shared/static/mgkn92xck0z05v7yjq8pqziukxvc2461.png\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "In this case, we have data points of Class A and B. We want to predict what the star (test data point) is. If we consider a k value of 3 (3 nearest data points) we will obtain a prediction of Class B. Yet if we consider a k value of 6, we will obtain a prediction of Class A."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "In this sense, it is important to consider the value of k. But hopefully from this diagram, you should get a sense of what the K-Nearest Neighbors algorithm is. It considers the 'K' Nearest Neighbors (points) when it predicts the classification of the test point."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<h1>Table of contents</h1>\n",
    "\n",
    "<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
    "    <ol>\n",
    "        <li><a href=\"#about_dataset\">About the dataset</a></li>\n",
    "        <li><a href=\"#visualization_analysis\">Data Visualization and Analysis</a></li>\n",
    "        <li><a href=\"#classification\">Classification</a></li>\n",
    "    </ol>\n",
    "</div>\n",
    "<br>\n",
    "<hr>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Lets load required libraries"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "import itertools\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.ticker import NullFormatter\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.ticker as ticker\n",
    "from sklearn import preprocessing\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[0;31mType:\u001b[0m        module\n",
       "\u001b[0;31mString form:\u001b[0m <module 'itertools' (built-in)>\n",
       "\u001b[0;31mDocstring:\u001b[0m  \n",
       "Functional tools for creating and using iterators.\n",
       "\n",
       "Infinite iterators:\n",
       "count(start=0, step=1) --> start, start+step, start+2*step, ...\n",
       "cycle(p) --> p0, p1, ... plast, p0, p1, ...\n",
       "repeat(elem [,n]) --> elem, elem, elem, ... endlessly or up to n times\n",
       "\n",
       "Iterators terminating on the shortest input sequence:\n",
       "accumulate(p[, func]) --> p0, p0+p1, p0+p1+p2\n",
       "chain(p, q, ...) --> p0, p1, ... plast, q0, q1, ... \n",
       "chain.from_iterable([p, q, ...]) --> p0, p1, ... plast, q0, q1, ... \n",
       "compress(data, selectors) --> (d[0] if s[0]), (d[1] if s[1]), ...\n",
       "dropwhile(pred, seq) --> seq[n], seq[n+1], starting when pred fails\n",
       "groupby(iterable[, keyfunc]) --> sub-iterators grouped by value of keyfunc(v)\n",
       "filterfalse(pred, seq) --> elements of seq where pred(elem) is False\n",
       "islice(seq, [start,] stop [, step]) --> elements from\n",
       "       seq[start:stop:step]\n",
       "starmap(fun, seq) --> fun(*seq[0]), fun(*seq[1]), ...\n",
       "tee(it, n=2) --> (it1, it2 , ... itn) splits one iterator into n\n",
       "takewhile(pred, seq) --> seq[0], seq[1], until pred fails\n",
       "zip_longest(p, q, ...) --> (p[0], q[0]), (p[1], q[1]), ... \n",
       "\n",
       "Combinatoric generators:\n",
       "product(p, q, ... [repeat=1]) --> cartesian product\n",
       "permutations(p[, r])\n",
       "combinations(p, r)\n",
       "combinations_with_replacement(p, r)\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "itertools?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[0;31mType:\u001b[0m        module\n",
       "\u001b[0;31mString form:\u001b[0m <module 'matplotlib.pyplot' from '/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages/matplotlib/pyplot.py'>\n",
       "\u001b[0;31mFile:\u001b[0m        ~/conda/envs/python/lib/python3.6/site-packages/matplotlib/pyplot.py\n",
       "\u001b[0;31mDocstring:\u001b[0m  \n",
       "`matplotlib.pyplot` is a state-based interface to matplotlib. It provides\n",
       "a MATLAB-like way of plotting.\n",
       "\n",
       "pyplot is mainly intended for interactive plots and simple cases of\n",
       "programmatic plot generation::\n",
       "\n",
       "    import numpy as np\n",
       "    import matplotlib.pyplot as plt\n",
       "\n",
       "    x = np.arange(0, 5, 0.1)\n",
       "    y = np.sin(x)\n",
       "    plt.plot(x, y)\n",
       "\n",
       "The object-oriented API is recommended for more complex plots.\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[0;31mInit signature:\u001b[0m \u001b[0mNullFormatter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
       "\u001b[0;31mDocstring:\u001b[0m      Always return the empty string.\n",
       "\u001b[0;31mFile:\u001b[0m           ~/conda/envs/python/lib/python3.6/site-packages/matplotlib/ticker.py\n",
       "\u001b[0;31mType:\u001b[0m           type\n",
       "\u001b[0;31mSubclasses:\u001b[0m     \n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "NullFormatter? #useful for `logit` scale"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[0;31mType:\u001b[0m        module\n",
       "\u001b[0;31mString form:\u001b[0m <module 'matplotlib.ticker' from '/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages/matplotlib/ticker.py'>\n",
       "\u001b[0;31mFile:\u001b[0m        ~/conda/envs/python/lib/python3.6/site-packages/matplotlib/ticker.py\n",
       "\u001b[0;31mDocstring:\u001b[0m  \n",
       "Tick locating and formatting\n",
       "============================\n",
       "\n",
       "This module contains classes to support completely configurable tick\n",
       "locating and formatting. Although the locators know nothing about major\n",
       "or minor ticks, they are used by the Axis class to support major and\n",
       "minor tick locating and formatting. Generic tick locators and\n",
       "formatters are provided, as well as domain specific custom ones.\n",
       "\n",
       "Default Formatter\n",
       "-----------------\n",
       "\n",
       "The default formatter identifies when the x-data being plotted is a\n",
       "small range on top of a large offset. To reduce the chances that the\n",
       "ticklabels overlap, the ticks are labeled as deltas from a fixed offset.\n",
       "For example::\n",
       "\n",
       "   ax.plot(np.arange(2000, 2010), range(10))\n",
       "\n",
       "will have tick of 0-9 with an offset of +2e3. If this is not desired\n",
       "turn off the use of the offset on the default formatter::\n",
       "\n",
       "   ax.get_xaxis().get_major_formatter().set_useOffset(False)\n",
       "\n",
       "set the rcParam ``axes.formatter.useoffset=False`` to turn it off\n",
       "globally, or set a different formatter.\n",
       "\n",
       "Tick locating\n",
       "-------------\n",
       "\n",
       "The Locator class is the base class for all tick locators. The locators\n",
       "handle autoscaling of the view limits based on the data limits, and the\n",
       "choosing of tick locations. A useful semi-automatic tick locator is\n",
       "`MultipleLocator`. It is initialized with a base, e.g., 10, and it picks\n",
       "axis limits and ticks that are multiples of that base.\n",
       "\n",
       "The Locator subclasses defined here are\n",
       "\n",
       ":class:`AutoLocator`\n",
       "    `MaxNLocator` with simple defaults.  This is the default tick locator for\n",
       "    most plotting.\n",
       "\n",
       ":class:`MaxNLocator`\n",
       "    Finds up to a max number of intervals with ticks at nice locations.\n",
       "\n",
       ":class:`LinearLocator`\n",
       "    Space ticks evenly from min to max.\n",
       "\n",
       ":class:`LogLocator`\n",
       "    Space ticks logarithmically from min to max.\n",
       "\n",
       ":class:`MultipleLocator`\n",
       "    Ticks and range are a multiple of base; either integer or float.\n",
       "\n",
       ":class:`FixedLocator`\n",
       "    Tick locations are fixed.\n",
       "\n",
       ":class:`IndexLocator`\n",
       "    Locator for index plots (e.g., where ``x = range(len(y))``).\n",
       "\n",
       ":class:`NullLocator`\n",
       "    No ticks.\n",
       "\n",
       ":class:`SymmetricalLogLocator`\n",
       "    Locator for use with with the symlog norm; works like `LogLocator` for the\n",
       "    part outside of the threshold and adds 0 if inside the limits.\n",
       "\n",
       ":class:`LogitLocator`\n",
       "    Locator for logit scaling.\n",
       "\n",
       ":class:`OldAutoLocator`\n",
       "    Choose a `MultipleLocator` and dynamically reassign it for intelligent\n",
       "    ticking during navigation.\n",
       "\n",
       ":class:`AutoMinorLocator`\n",
       "    Locator for minor ticks when the axis is linear and the\n",
       "    major ticks are uniformly spaced.  Subdivides the major\n",
       "    tick interval into a specified number of minor intervals,\n",
       "    defaulting to 4 or 5 depending on the major interval.\n",
       "\n",
       "\n",
       "There are a number of locators specialized for date locations - see\n",
       "the `dates` module.\n",
       "\n",
       "You can define your own locator by deriving from Locator. You must\n",
       "override the ``__call__`` method, which returns a sequence of locations,\n",
       "and you will probably want to override the autoscale method to set the\n",
       "view limits from the data limits.\n",
       "\n",
       "If you want to override the default locator, use one of the above or a custom\n",
       "locator and pass it to the x or y axis instance. The relevant methods are::\n",
       "\n",
       "  ax.xaxis.set_major_locator(xmajor_locator)\n",
       "  ax.xaxis.set_minor_locator(xminor_locator)\n",
       "  ax.yaxis.set_major_locator(ymajor_locator)\n",
       "  ax.yaxis.set_minor_locator(yminor_locator)\n",
       "\n",
       "The default minor locator is `NullLocator`, i.e., no minor ticks on by default.\n",
       "\n",
       "Tick formatting\n",
       "---------------\n",
       "\n",
       "Tick formatting is controlled by classes derived from Formatter. The formatter\n",
       "operates on a single tick value and returns a string to the axis.\n",
       "\n",
       ":class:`NullFormatter`\n",
       "    No labels on the ticks.\n",
       "\n",
       ":class:`IndexFormatter`\n",
       "    Set the strings from a list of labels.\n",
       "\n",
       ":class:`FixedFormatter`\n",
       "    Set the strings manually for the labels.\n",
       "\n",
       ":class:`FuncFormatter`\n",
       "    User defined function sets the labels.\n",
       "\n",
       ":class:`StrMethodFormatter`\n",
       "    Use string `format` method.\n",
       "\n",
       ":class:`FormatStrFormatter`\n",
       "    Use an old-style sprintf format string.\n",
       "\n",
       ":class:`ScalarFormatter`\n",
       "    Default formatter for scalars: autopick the format string.\n",
       "\n",
       ":class:`LogFormatter`\n",
       "    Formatter for log axes.\n",
       "\n",
       ":class:`LogFormatterExponent`\n",
       "    Format values for log axis using ``exponent = log_base(value)``.\n",
       "\n",
       ":class:`LogFormatterMathtext`\n",
       "    Format values for log axis using ``exponent = log_base(value)``\n",
       "    using Math text.\n",
       "\n",
       ":class:`LogFormatterSciNotation`\n",
       "    Format values for log axis using scientific notation.\n",
       "\n",
       ":class:`LogitFormatter`\n",
       "    Probability formatter.\n",
       "\n",
       ":class:`EngFormatter`\n",
       "    Format labels in engineering notation\n",
       "\n",
       ":class:`PercentFormatter`\n",
       "    Format labels as a percentage\n",
       "\n",
       "You can derive your own formatter from the Formatter base class by\n",
       "simply overriding the ``__call__`` method. The formatter class has\n",
       "access to the axis view and data limits.\n",
       "\n",
       "To control the major and minor tick label formats, use one of the\n",
       "following methods::\n",
       "\n",
       "  ax.xaxis.set_major_formatter(xmajor_formatter)\n",
       "  ax.xaxis.set_minor_formatter(xminor_formatter)\n",
       "  ax.yaxis.set_major_formatter(ymajor_formatter)\n",
       "  ax.yaxis.set_minor_formatter(yminor_formatter)\n",
       "\n",
       "See :doc:`/gallery/ticks_and_spines/major_minor_demo` for an\n",
       "example of setting major and minor ticks. See the :mod:`matplotlib.dates`\n",
       "module for more information and examples of using date locators and formatters.\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ticker?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true,
    "jupyter": {
     "outputs_hidden": true
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\u001b[0;31mType:\u001b[0m        module\n",
       "\u001b[0;31mString form:\u001b[0m <module 'sklearn.preprocessing' from '/home/jupyterlab/conda/envs/python/lib/python3.6/site-packages/sklearn/preprocessing/__init__.py'>\n",
       "\u001b[0;31mFile:\u001b[0m        ~/conda/envs/python/lib/python3.6/site-packages/sklearn/preprocessing/__init__.py\n",
       "\u001b[0;31mDocstring:\u001b[0m  \n",
       "The :mod:`sklearn.preprocessing` module includes scaling, centering,\n",
       "normalization, binarization and imputation methods.\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "preprocessing?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "<div id=\"about_dataset\">\n",
    "    <h2>About the dataset</h2>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Imagine a telecommunications provider has segmented its customer base by service usage patterns, categorizing the customers into four groups. If demographic data can be used to predict group membership, the company can customize offers for individual prospective customers. It is a classification problem. That is, given the dataset,  with predefined labels, we need to build a model to be used to predict class of a new or unknown case. \n",
    "\n",
    "The example focuses on using demographic data, such as region, age, and marital, to predict usage patterns. \n",
    "\n",
    "The target field, called __custcat__, has four possible values that correspond to the four customer groups, as follows:\n",
    "  1- Basic Service\n",
    "  2- E-Service\n",
    "  3- Plus Service\n",
    "  4- Total Service\n",
    "\n",
    "Our objective is to build a classifier, to predict the class of unknown cases. We will use a specific type of classification called K nearest neighbour.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Lets download the dataset. To download the data, we will use !wget to download it from IBM Object Storage."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "--2019-10-04 11:01:20--  https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/ML0101ENv3/labs/teleCust1000t.csv\n",
      "Resolving s3-api.us-geo.objectstorage.softlayer.net (s3-api.us-geo.objectstorage.softlayer.net)... 67.228.254.193\n",
      "Connecting to s3-api.us-geo.objectstorage.softlayer.net (s3-api.us-geo.objectstorage.softlayer.net)|67.228.254.193|:443... connected.\n",
      "HTTP request sent, awaiting response... 200 OK\n",
      "Length: 37048 (36K) [text/csv]\n",
      "Saving to: ‘teleCust1000t.csv’\n",
      "\n",
      "teleCust1000t.csv   100%[===================>]  36.18K  --.-KB/s    in 0.02s   \n",
      "\n",
      "2019-10-04 11:01:20 (1.66 MB/s) - ‘teleCust1000t.csv’ saved [37048/37048]\n",
      "\n"
     ]
    }
   ],
   "source": [
    "!wget -O teleCust1000t.csv https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/ML0101ENv3/labs/teleCust1000t.csv"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "__Did you know?__ When it comes to Machine Learning, you will likely be working with large datasets. As a business, where can you host your data? IBM is offering a unique opportunity for businesses, with 10 Tb of IBM Cloud Object Storage: [Sign up now for free](http://cocl.us/ML0101EN-IBM-Offer-CC)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "### Load Data From CSV File  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>region</th>\n",
       "      <th>tenure</th>\n",
       "      <th>age</th>\n",
       "      <th>marital</th>\n",
       "      <th>address</th>\n",
       "      <th>income</th>\n",
       "      <th>ed</th>\n",
       "      <th>employ</th>\n",
       "      <th>retire</th>\n",
       "      <th>gender</th>\n",
       "      <th>reside</th>\n",
       "      <th>custcat</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>13</td>\n",
       "      <td>44</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>64.0</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>11</td>\n",
       "      <td>33</td>\n",
       "      <td>1</td>\n",
       "      <td>7</td>\n",
       "      <td>136.0</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>68</td>\n",
       "      <td>52</td>\n",
       "      <td>1</td>\n",
       "      <td>24</td>\n",
       "      <td>116.0</td>\n",
       "      <td>1</td>\n",
       "      <td>29</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>33</td>\n",
       "      <td>33</td>\n",
       "      <td>0</td>\n",
       "      <td>12</td>\n",
       "      <td>33.0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>23</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "      <td>9</td>\n",
       "      <td>30.0</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   region  tenure  age  marital  address  income  ed  employ  retire  gender  \\\n",
       "0       2      13   44        1        9    64.0   4       5     0.0       0   \n",
       "1       3      11   33        1        7   136.0   5       5     0.0       0   \n",
       "2       3      68   52        1       24   116.0   1      29     0.0       1   \n",
       "3       2      33   33        0       12    33.0   2       0     0.0       1   \n",
       "4       2      23   30        1        9    30.0   1       2     0.0       0   \n",
       "\n",
       "   reside  custcat  \n",
       "0       2        1  \n",
       "1       6        4  \n",
       "2       2        3  \n",
       "3       1        1  \n",
       "4       4        3  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('teleCust1000t.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "<div id=\"visualization_analysis\">\n",
    "    <h2>Data Visualization and Analysis</h2> \n",
    "</div>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "#### Let’s see how many of each class is in our data set "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3    281\n",
       "1    266\n",
       "4    236\n",
       "2    217\n",
       "Name: custcat, dtype: int64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['custcat'].value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "#### 281 Plus Service, 266 Basic-service, 236 Total Service, and 217 E-Service customers\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You can easily explore your data using visualization techniques:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[<matplotlib.axes._subplots.AxesSubplot object at 0x7fc77c9b70b8>]],\n",
       "      dtype=object)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYMAAAEICAYAAAC9E5gJAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAASIUlEQVR4nO3dfbBcdX3H8feHYMES5aFgJk2iN9SUEWTqwy3qoPam0IKihNpi41AbKk7qFDva2qlBOq39g05sp452kDqpMEaxXFKQISPDKJN6q51qkSBPAVOiBAjEpCIIUUsb/PaPPddu0nuTu7m7e3fh/Zq5s2d/+ztnP3tY7ueesw9JVSFJem47bK4DSJLmnmUgSbIMJEmWgSQJy0CShGUgScIy0LNMki1JxuY6hzRs4ucMJEkeGUiSLAM9uyTZnuTMJB9OsiHJZ5I81Zw+Gm2btyTJ55P8Z5LHklzejB+W5M+SPJhkd7P+0c1tI0kqye8leTjJ40nek+SXk9yV5InJ7bTdz7uS3NfM/WKSl/R3j0gzYxno2excYBw4BtgITP7Cnwd8AXgQGAEWNfMALmx+lgMnAvMn12vzGmAZ8NvAx4BLg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OSvGBymdYLhPc0+VY101YBNzbLA5G7zT5/NQ36/m7T0f5tTiU9leS1zXPtd9vW6Zu0/vGqDwLnVtWP2sZPSOvfMyHJiU3u7wxC7k6fE4OQuc2ZwLeq6qenf7q+r3v5ynivfoA303qXzreBS+c6z37ZXk/rkOwu4I7m583AZ4G7m/GNwMK2dS5tHstWevxuhQPkPpHWOyruBLZM7lfg54BNwP3N5XGDlLvJ8bPAY8DRbWMDt79pldVO4H9o/fV20aHsX2CU1i+ybwOX03yTQJ9zb6N1nn3yOf7JZu5vNs+fO4HbgbfORe5pMnf8nBiEfd2Mfxp4z35zu7qv/ToKSdJQniaSJHWZZSBJsgwkSZaBJAnLQJKEZSBJwjKQJAH/C+ch7ZHoZktOAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "df.hist(column='income', bins=50)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "### Feature set"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Lets define feature sets, X:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['region', 'tenure', 'age', 'marital', 'address', 'income', 'ed',\n",
       "       'employ', 'retire', 'gender', 'reside', 'custcat'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "To use scikit-learn library, we have to convert the Pandas data frame to a Numpy array:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  2.,  13.,  44.,   1.,   9.,  64.,   4.,   5.,   0.,   0.,   2.],\n",
       "       [  3.,  11.,  33.,   1.,   7., 136.,   5.,   5.,   0.,   0.,   6.],\n",
       "       [  3.,  68.,  52.,   1.,  24., 116.,   1.,  29.,   0.,   1.,   2.],\n",
       "       [  2.,  33.,  33.,   0.,  12.,  33.,   2.,   0.,   0.,   1.,   1.],\n",
       "       [  2.,  23.,  30.,   1.,   9.,  30.,   1.,   2.,   0.,   0.,   4.]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = df[['region', 'tenure','age', 'marital', 'address', 'income', 'ed', 'employ','retire', 'gender', 'reside']] .values  #.astype(float)\n",
    "X[0:5]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "What are our labels?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 4, 3, 1, 3])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y = df['custcat'].values\n",
    "y[0:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "## Normalize Data "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Data Standardization give data zero mean and unit variance, it is good practice, especially for algorithms such as KNN which is based on distance of cases:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.02696767, -1.055125  ,  0.18450456,  1.0100505 , -0.25303431,\n",
       "        -0.12650641,  1.0877526 , -0.5941226 , -0.22207644, -1.03459817,\n",
       "        -0.23065004],\n",
       "       [ 1.19883553, -1.14880563, -0.69181243,  1.0100505 , -0.4514148 ,\n",
       "         0.54644972,  1.9062271 , -0.5941226 , -0.22207644, -1.03459817,\n",
       "         2.55666158],\n",
       "       [ 1.19883553,  1.52109247,  0.82182601,  1.0100505 ,  1.23481934,\n",
       "         0.35951747, -1.36767088,  1.78752803, -0.22207644,  0.96655883,\n",
       "        -0.23065004],\n",
       "       [-0.02696767, -0.11831864, -0.69181243, -0.9900495 ,  0.04453642,\n",
       "        -0.41625141, -0.54919639, -1.09029981, -0.22207644,  0.96655883,\n",
       "        -0.92747794],\n",
       "       [-0.02696767, -0.58672182, -0.93080797,  1.0100505 , -0.25303431,\n",
       "        -0.44429125, -1.36767088, -0.89182893, -0.22207644, -1.03459817,\n",
       "         1.16300577]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = preprocessing.StandardScaler().fit(X).transform(X.astype(float))\n",
    "X[0:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "### Train Test Split  \n",
    "Out of Sample Accuracy is the percentage of correct predictions that the model makes on data that that the model has NOT been trained on. Doing a train and test on the same dataset will most likely have low out-of-sample accuracy, due to the likelihood of being over-fit.\n",
    "\n",
    "It is important that our models have a high, out-of-sample accuracy, because the purpose of any model, of course, is to make correct predictions on unknown data. So how can we improve out-of-sample accuracy? One way is to use an evaluation approach called Train/Test Split.\n",
    "Train/Test Split involves splitting the dataset into training and testing sets respectively, which are mutually exclusive. After which, you train with the training set and test with the testing set. \n",
    "\n",
    "This will provide a more accurate evaluation on out-of-sample accuracy because the testing dataset is not part of the dataset that have been used to train the data. It is more realistic for real world problems.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train set: (800, 11) (800,)\n",
      "Test set: (200, 11) (200,)\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "X_train, X_test, y_train, y_test = train_test_split( X, y, test_size=0.2, random_state=4)\n",
    "print ('Train set:', X_train.shape,  y_train.shape)\n",
    "print ('Test set:', X_test.shape,  y_test.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "<div id=\"classification\">\n",
    "    <h2>Classification</h2>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "<h3>K nearest neighbor (KNN)</h3>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "#### Import library "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "Classifier implementing the k-nearest neighbors vote."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [],
   "source": [
    "from sklearn.neighbors import KNeighborsClassifier"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "### Training\n",
    "\n",
    "Lets start the algorithm with k=4 for now:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n",
       "           metric_params=None, n_jobs=None, n_neighbors=4, p=2,\n",
       "           weights='uniform')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "k = 4\n",
    "#Train Model and Predict  \n",
    "neigh = KNeighborsClassifier(n_neighbors = k).fit(X_train,y_train)\n",
    "neigh"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "### Predicting\n",
    "we can use the model to predict the test set:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 1, 3, 2, 4])"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "yhat = neigh.predict(X_test)\n",
    "yhat[0:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "### Accuracy evaluation\n",
    "In multilabel classification, __accuracy classification score__ is a function that computes subset accuracy. This function is equal to the jaccard_similarity_score function. Essentially, it calculates how closely the actual labels and predicted labels are matched in the test set."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train set Accuracy:  0.5475\n",
      "Test set Accuracy:  0.32\n"
     ]
    }
   ],
   "source": [
    "from sklearn import metrics\n",
    "print(\"Train set Accuracy: \", metrics.accuracy_score(y_train, neigh.predict(X_train)))\n",
    "print(\"Test set Accuracy: \", metrics.accuracy_score(y_test, yhat))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Practice\n",
    "Can you build the model again, but this time with k=6?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Train set Accuracy:  0.51625\n",
      "Test set Accuracy:  0.31\n"
     ]
    }
   ],
   "source": [
    "# write your code here\n",
    "k = 6\n",
    "neigh6 = KNeighborsClassifier(n_neighbors = k).fit(X_train,y_train)\n",
    "yhat6 = neigh6.predict(X_test)\n",
    "print(\"Train set Accuracy: \", metrics.accuracy_score(y_train, neigh6.predict(X_train)))\n",
    "print(\"Test set Accuracy: \", metrics.accuracy_score(y_test, yhat6))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "jupyter": {
     "source_hidden": true
    }
   },
   "source": [
    "Double-click __here__ for the solution.\n",
    "\n",
    "<!-- Your answer is below:\n",
    "    \n",
    "    \n",
    "k = 6\n",
    "neigh6 = KNeighborsClassifier(n_neighbors = k).fit(X_train,y_train)\n",
    "yhat6 = neigh6.predict(X_test)\n",
    "print(\"Train set Accuracy: \", metrics.accuracy_score(y_train, neigh6.predict(X_train)))\n",
    "print(\"Test set Accuracy: \", metrics.accuracy_score(y_test, yhat6))\n",
    "\n",
    "-->"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "#### What about other K?\n",
    "K in KNN, is the number of nearest neighbors to examine. It is supposed to be specified by the User. So, how can we choose right value for K?\n",
    "The general solution is to reserve a part of your data for testing the accuracy of the model. Then chose k =1, use the training part for modeling, and calculate the accuracy of prediction using all samples in your test set. Repeat this process, increasing the k, and see which k is the best for your model.\n",
    "\n",
    "We can calculate the accuracy of KNN for different Ks."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.3  , 0.29 , 0.315, 0.32 , 0.315, 0.31 , 0.335, 0.325, 0.34 ])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "Ks = 10\n",
    "mean_acc = np.zeros((Ks-1))\n",
    "std_acc = np.zeros((Ks-1))\n",
    "ConfustionMx = [];\n",
    "for n in range(1,Ks):\n",
    "    \n",
    "    #Train Model and Predict  \n",
    "    neigh = KNeighborsClassifier(n_neighbors = n).fit(X_train,y_train)\n",
    "    yhat=neigh.predict(X_test)\n",
    "    mean_acc[n-1] = metrics.accuracy_score(y_test, yhat)\n",
    "\n",
    "    \n",
    "    std_acc[n-1]=np.std(yhat==y_test)/np.sqrt(yhat.shape[0])\n",
    "\n",
    "mean_acc"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "#### Plot  model accuracy  for Different number of Neighbors "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAagAAAEYCAYAAAAJeGK1AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXiU9bXA8e+ZLRsJmyirggIqKksI4IK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CqehzRFkD/kB8OxzsBuEJVTwcuBWY7TYB7AYvY10lEzyiL9Spws6p+VOX+QqC6JGdMJUtQJi05Xd6fBW6pxdMWOGdulQErgYojDj4j+uFe4WVVjTiHs60CjiLaI+9ypwXVPKA10M25fr6qrq7m/foBc52moCHgBaLnKsXz/a0G5hNNHLGOdaqkz4hWNMccIO6BwHPOay4Dvga6O9f/S1UrzklbAFzlzOUd55xHVlU7otVdrLeBa6tJpJuIduo2pkaWoEw6e4hoBRF7NlEI5+feacQZO49TFvN1JOZ2hL37VlbtD6aAAGNUtbfzp0vMGT67aohP4v1GanAP8Bv2/nf8DNGK5Tjgj0DsUeE1xV2TyridQz0HET2F9jkRubya6/dUeT+Am53/jq1yf6ZzvTE1sgRl0pbz2//L7D3M9RXQ1/l6GNETf2vrEhHxOPNShwPLgdnATyV6HAoi0l0OfGjfPOAUETnIqTBGET2ZNC5OxbOUvedycoH1Thyj44j7g4rrRKQ7cKhz/15E5DCi52c9RbSjfnXHaXwOdK1yX8T5vo4Ukbti7u+Oy7qyG/exBGXS3QNA7Gq+p4gmhfnAAGqubvZnOdFE8hZwo6qWEp2nWgoUi8hi4EkOcFqAqq4Hfgu8R/TAt2JVrbrI4ED+TPRgyAq/J5r4/sW+x5xUF/dYwOsMCb4EXOkMcVZ1KrBIRBYCFwEPV3PNP53r9uK83jCiK/ducu4+zbnemBpZN3NjTEJI9Pyv94ieABzez3WHED025IwGC840SpagjDEJIyLnED1Q85v9XNMPKFfV6lYCGlPJEpQxxhhXsjkoY4wxrmQJyhhjjCtZgjLGGONKlqCMMca4kiUoY4wxrvT/ha5Tfj36CLwAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.plot(range(1,Ks),mean_acc,'g')\n",
    "plt.fill_between(range(1,Ks),mean_acc - 1 * std_acc,mean_acc + 1 * std_acc, alpha=0.10)\n",
    "plt.legend(('Accuracy ', '+/- 3xstd'))\n",
    "plt.ylabel('Accuracy ')\n",
    "plt.xlabel('Number of Nabors (K)')\n",
    "plt.tight_layout()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The best accuracy was with 0.34 with k= 9\n"
     ]
    }
   ],
   "source": [
    "print( \"The best accuracy was with\", mean_acc.max(), \"with k=\", mean_acc.argmax()+1) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "button": false,
    "deletable": true,
    "new_sheet": false,
    "run_control": {
     "read_only": false
    }
   },
   "source": [
    "<h2>Want to learn more?</h2>\n",
    "\n",
    "IBM SPSS Modeler is a comprehensive analytics platform that has many machine learning algorithms. It has been designed to bring predictive intelligence to decisions made by individuals, by groups, by systems – by your enterprise as a whole. A free trial is available through this course, available here: <a href=\"http://cocl.us/ML0101EN-SPSSModeler\">SPSS Modeler</a>\n",
    "\n",
    "Also, you can use Watson Studio to run these notebooks faster with bigger datasets. Watson Studio is IBM's leading cloud solution for data scientists, built by data scientists. With Jupyter notebooks, RStudio, Apache Spark and popular libraries pre-packaged in the cloud, Watson Studio enables data scientists to collaborate on their projects without having to install anything. Join the fast-growing community of Watson Studio users today with a free account at <a href=\"https://cocl.us/ML0101EN_DSX\">Watson Studio</a>\n",
    "\n",
    "<h3>Thanks for completing this lesson!</h3>\n",
    "\n",
    "<h4>Author:  <a href=\"https://ca.linkedin.com/in/saeedaghabozorgi\">Saeed Aghabozorgi</a></h4>\n",
    "<p><a href=\"https://ca.linkedin.com/in/saeedaghabozorgi\">Saeed Aghabozorgi</a>, PhD is a Data Scientist in IBM with a track record of developing enterprise level applications that substantially increases clients’ ability to turn data into actionable knowledge. He is a researcher in data mining field and expert in developing advanced analytic methods like machine learning and statistical modelling on large datasets.</p>\n",
    "\n",
    "<hr>\n",
    "\n",
    "<p>Copyright &copy; 2018 <a href=\"https://cocl.us/DX0108EN_CC\">Cognitive Class</a>. This notebook and its source code are released under the terms of the <a href=\"https://bigdatauniversity.com/mit-license/\">MIT License</a>.</p>"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python",
   "language": "python",
   "name": "conda-env-python-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
